#include "OgreGLESFBOMultiRenderTarget.h"
#include "OgreGLESPixelFormat.h"
#include "OgreRoot.h"
#include "OgreGLESHardwarePixelBuffer.h"

namespace Ogre
{
	GLESFBOMultiRenderTarget::GLESFBOMultiRenderTarget(GLESFBOManager* manager, const String& name):
		MultiRenderTarget(name),
		fbo(manager, 0)
	{
	}

	GLESFBOMultiRenderTarget::~GLESFBOMultiRenderTarget()s
	{
	}

	void GLESFBOMultiRenderTarget::bindSurfaceImpl(size_t attachment, RenderTexture* target)
	{
		GLESFrameBufferObject* fbobj = 0;
		target->getCustomAttribute("FBO", &fbobj);
		assert(fbobj);
		fbo.bindSurface(attachment, fbobj->getSurface(0));
		GL_CHECK_ERROR;

		mWidth = fbo.getWidth();
		mHeight = fbo.getHeight();
	}

	void GLESFBOMultiRenderTarget::unbindSurfaceImpl(size_t attachment)
	{
		fbo.unbindSurface(attachment);
		GL_CHECK_ERROR;

		mWidth = fbo.getWidth();
		mHeight = fbo.getHeight();
	}

	void GLESFBOMultiRenderTarget::getCustomAttribute(const String& name, void* pData)
	{
		if (name == "FBO")
		{
			*static_cast<GLESFrameBufferObject**>(pData) = &fbo;
		}
	}
}
